package game;

import game.server.GameHelper;
import gamestate.LTD;

import java.util.LinkedList;
import java.util.List;

import domain.Agent;
import domain.SedResponse;
import domain.Task;
import domain.SedResponse.Status;


public class Game {
	
	private static Game current = null;
	
	public static Game current(){
		return current;
	}
	
	public static Game newGame(){
		current = new Game();
		return current();
	}
	
	private Game(){
		super();
		gameHelper = new GameHelper();
	}
	
	
	private GameHelper gameHelper;
	
	public Integer turn = 0;
	
	public Integer money;
	
	public List<Agent> agents;
	
	public List<Task> tasks;
	
	public LTD company;
	
	public LTD enemy;
	
	
	private List<SedResponse> respones = new LinkedList<SedResponse>();
	
	/**
	 * 
	 * @return true is started
	 */
	public boolean start(){
		
		SedResponse resp = gameHelper.startGame();
		
		return resp != null && SedResponse.Status.FIRST_TURN == resp.getStatus();
		
	}

	public SedResponse getLastResponse() {
		if(respones.isEmpty()) return new SedResponse();
		return respones.get(respones.size() - 1);
	}

	public void requestStatus() {
		
		SedResponse resp = gameHelper.getStatus();
		this.turn = resp.turn;
		respones.add(resp);		
	}
	
	
	
}
